#include <stdio.h>

int islandPerimeter(int** grid, int gridSize, int* gridColSize) {
    int land = 0;
    for (int i = 0; i < gridSize; i++)
    {
        for (int j = 0; j < gridColSize[i]; j++)
        {
            if (grid[i][j] == 1)
            {
                land += 4;
                if (i < gridSize - 1 && grid[i + 1][j] == 1)
                    land -= 2;
                if (j < gridColSize[i] - 1 && grid[i][j + 1] == 1)
                    land -= 2;
            }
        }
    }
    return land;
}


int main()
{

    int grid[4][4] = { {0,1,0,0,},{1,1,1,0},{0,1,0,0},{1,1,0,0} };
    int gridSize = 16;
    int gridColSize = 4;
    int result = islandPerimeter(grid, 16, &gridColSize);
    printf("%d\n", result);
	return 0;
}